define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'outsidestudent/index' + location.search,
                    // add_url: 'outsidestudent/add',
                    // edit_url: 'outsidestudent/edit',
                    // del_url: 'outsidestudent/del',
                    multi_url: 'outsidestudent/multi',
                    table: 'outsidestudent',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'),operate:false},
                        {field: 'nickname', title: __('Nickname')},

                        {field: 'card_pic', title: __('Card_pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'exam_pic', title: __('Exam_pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'healthy_pic', title: __('Healthy_pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'tel', title: __('Tel')},
                        {field: 'high_school', title: __('High_school')},
                        {field: 'admission_time', title: __('Admission_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD'},
                        {field: 'guarder_name', title: __('Guarder_name')},
                        {field: 'relevance', title: __('Relevance')},

                        {field: 'guarder_card_pic', title: __('Guarder_card_pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'guarder_healthy_pic', title: __('Guarder_healthy_pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'guarder_tel', title: __('Guarder_tel')},
                        {field: 'work_unit', title: __('Work_unit')},
                        // {field: 'status', title: __('Status')},
                        {field: 'status',title:'状态',
                            formatter: function (value,row,index) {
                                if(value == 1) {
                                    return '<a href="javascript:;" class="btn btn-xs btn-success">已审核</a>';
                                }else if(value == 2){
                                    return '<a href="javascript:;" class="btn btn-xs btn-danger">已驳回</a>';
                                }else{
                                    return '<a class="btn btn-primary btn-xs">待审核</a>';
                                }

                            },
                            searchList: {"0": __('待审核'), "1": __('已审核'), "2": __('已驳回')}
                        },

                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'dispatch',
                                    text: '',
                                    icon: 'fa fa-check',
                                    title: '审核',
                                    classname: 'btn btn-warning btn-xs btn-magic btn-ajax',
                                    url: 'outsidestudent/check',
                                    
                                    confirm: '确定要审核吗？',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },{
                                    name: 'dispatch',
                                    text: '',
                                    icon: 'fa fa-backward',
                                    title: '驳回',
                                    classname: 'btn btn-info btn-xs btn-magic btn-ajax',
                                    url: 'outsidestudent/reject',
                                    confirm: '确定要驳回吗？',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }

                                }
                            ],
                            formatter: function (value, row, index) {
                                if(row.status == 0){
                                    return Table.api.formatter.operate.call(this, value, row, index);
                                }
                            },

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});